package com.exchange.controller;


import com.alibaba.fastjson2.JSON;
import com.exchange.entity.model.ReservationModel;
import com.exchange.entity.pojo.User;
import com.exchange.entity.vo.MapVo;
import com.exchange.entity.vo.StarsAddressVo;
import com.exchange.service.MapService;

import com.exchange.until.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 地图的api接口
 *
 * @Author : RulerWood
 * @Data : 2024/4/24 - 1
 * @9:40
 */
@Slf4j
@RestController
@Tag(name = "地图")
@RequestMapping("/jeecg-boot")
public class MapController {
    @Autowired
    private MapService mapService;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    /**
     * 地图中的点位标记
     * 包含地图的经纬度以及充电桩的数量
     *
     * @return
     */
    @GetMapping("/getAllPoint")
    @Operation(summary = "获取所有标记位置")
    public Result<List<MapVo>> getAllPoint() {
        return Result.success(this.mapService.getAllPoint());
    }

    /**
     * 打开搜索框时调用
     *
     * @param token 用户登录的信息
     * @return
     */
    @GetMapping("/addressAuxi")
    @Operation(summary = "搜索框的点击显示")
    public Result<Map<String, List<StarsAddressVo>>> addressAuxi(@RequestHeader String token) {
        return this.mapService.getAddressAuxi(token);
    }

    /**
     * @param token 用户登录的信息
     * @return
     */
    @GetMapping("/searchTheFrame")
    @Operation(summary = "用户搜索记录redis")
    public Result searchTheFrame(@RequestHeader String token, String address) {
        return Result.success(this.mapService.searchTheFrame(token, address));
    }

    /**
     * 查看当前用户是否有预约，如果没有则交由rabbitmq去操作
     * @param id 电站主键
     * @return
     */
    @GetMapping("/reservation")
    @Operation(summary = "用户是否有预约")
    public Result<String> reservation(@RequestParam(value = "id") Long id, @RequestHeader("token") String token) {
        return this.mapService.reservation(id, token);
    }

    /**
     * 查询当前站点有没有该用户所适配的电池
     * @param token
     * @param pid
     * @return
     */
    @GetMapping("/findAllAvailableBatteryForSelf")
    @Operation(summary = "当前站点电池适配情况")
    public Result findAllAvailableBatteryForSelf(@RequestHeader("token") String token, @RequestParam("pid") Long pid) {
        return Result.success(this.mapService.findAllAvailableBatteryForSelf(token,pid));
    }


}
